home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Jun 20, 1997
- //<doc>
- //<name groupObjectsByName>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // string[] groupObjectsByName( string $objectList[], string $token )
- //
- //<description>
- // Given a list of strings, this procedure groups the strings into
- // lists with the same object.
- //
- //<flags>
- // string[] $objectList List of objects to be grouped
- // string $token Seperator at which the object grouping is defined
- //
- //<returns>
- // string[] : $objectList, grouped by types separated by $token
- //
- //<examples>
- // string $objectList[] = { "curve1.cv[1]",
- // "curve1.u[0.3]",
- // "curve3.cv[2]",
- // "curve4.cv[0]",
- // "curve1.cv[0]" };
- // groupObjectsByName($objectList, ".");
- // // Result : { "curve1.cv[1] curve1.u[0.3] curve1.cv[0]",
- // "curve3.cv[2]", "curve4.cv[0]" } //
- //
- // // The token is the string that limits the object name. Changing
- // // the token gives different results.
- // //
- // groupObjectsByName($objectList, "[");
- // // Result : { "curve1.cv[1] curve1.cv[0]", "curve1.u[0.3]",
- // "curve3.cv[2]", "curve4.cv[0]" } //
- //
- //</doc>
- //
-
- proc int foundObjectInList( string $name, string $listOfNames[] )
- //
- // Description:
- // This procedure returns true if the given name was found in the
- // list of names. WARNING: this is a slow algorithm and is not
- // efficient when dealing with a long list of names.
- //
- {
- int $index = -1;
- int $foundName = false;
- int $numNames = size( $listOfNames );
- for( $i = 0; $i < $numNames; $i ++ )
- {
- if( $name == $listOfNames[$i] )
- {
- $foundName = true;
- $index = $i;
- return $index;
- }
- }
-
- return $index;
- }
-
- global proc string[] groupObjectsByName( string $objectList[], string $token )
- {
- string $processedNames[];
- string $argList[];
- int $i;
-
- // for each object in objectList, try to group it with previous objects
- //
- int $numObjects = size($objectList);
-
- for( $i = 0; $i < $numObjects; $i ++ )
- {
- string $objectName[];
- $numTokens = `tokenize $objectList[$i] $token $objectName`;
-
- if( $numTokens > 0 )
- {
- int $index = foundObjectInList( $objectName[0], $processedNames );
- if( $index >= 0 )
- {
- // Concatenate the string
- //
- $argList[$index] = $argList[$index] + " ";
- $argList[$index] = $argList[$index] + $objectList[$i];
- }
- else
- {
- // Add this name to the $processedNames
- //
- int $processedNamesSize = size( $processedNames );
- $processedNames[$processedNamesSize] = $objectName[0];
-
- // start a new arg string
- //
- int $argSize = size( $argList );
- $argList[$argSize] = $objectList[$i];
- }
- }
- }
- return $argList;
- }
-